#pragma once

#include <gexpl_dac.h>

// 设置给定DAC的12位数字值，参数直接为数字值，必须保证除低12位外全为0。
static inline void dac_set_12_bit_digital_by_u16(dac_dh_re dac_no_r,
						 u16_s digital) {
	dac_wreg_dh(dac_no_r, DAC_DH_R12DH_RR, digital);
}

// 设置给定DAC的12位数字值，参数为左对齐的数字值，必须保证低4位全为0。
static inline void dac_set_12_bit_digital_by_u16_left(dac_dh_re dac_no_r,
						      u16_s digital_left) {
	dac_wreg_dh(dac_no_r, DAC_DH_L12DH_RR, digital_left);
}

// 设置给定DAC的8位数字值，参数直接为数字值。
static inline void dac_set_8_bit_digital_by_u8(dac_dh_re dac_no_r,
					       u8_s digital) {
	dac_wreg_dh(dac_no_r, DAC_DH_R8DH_RR, digital);
}

// 并发设置两个DAC的12位数字值，参数直接为数字值，必须保证除低12位外全为0。
static inline void
dac_concurrent_set_12_bit_digital_by_u16(u16_s dac0_digital,
					 u16_s dac1_digital) {
	uint_16_32_s u1632 = {
		.u16_a[0] = dac0_digital,
		.u16_a[1] = dac1_digital,
	};
	dac_wreg_dh(DACC_DH_R, DAC_DH_R12DH_RR, u1632.u32);
}

// 并发设置两个DAC的12位数字值，参数为左对齐的数字值，必须保证除高12位外全为0。
static inline void
dac_concurrent_set_12_bit_digital_by_u16_left(u16_s dac0_digital_left,
					      u16_s dac1_digital_left) {
	uint_16_32_s u1632 = {
		.u16_a[0] = dac0_digital_left,
		.u16_a[1] = dac1_digital_left,
	};
	dac_wreg_dh(DACC_DH_R, DAC_DH_L12DH_RR, u1632.u32);
}

// 并发设置两个DAC的8位数字值，参数直接为数字值。
static inline void dac_concurrent_set_8_bit_digital_by_u8(u8_s dac0_digital,
							  u8_s dac1_digital) {
	uint_16_32_s u1632 = {
		.u16_a[0] = dac0_digital,
		.u16_a[1] = dac1_digital,
	};
	dac_wreg_dh(DACC_DH_R, DAC_DH_R8DH_RR, u1632.u32);
}
